﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Krile.Forms.MainForm.Controls
{
    public partial class InfoBar : UserControl
    {
        public InfoBar()
        {
            InitializeComponent();
        }

        public void UpdateDisplay()
        {
            if (InvokeRequired)
            {
                this.Invoke(new Action(UpdateDisplay));
                return;
            }
            if (Subsystem.Debugger.GetReportLength() == 0)
            {
                this.Visible = false;
            }
            else
            {
                this.Visible = true;
                displayArea.Refresh();
            }
        }

        private void CloseBtn_Click(object sender, EventArgs e)
        {
            Subsystem.Debugger.ClearReports();
            this.Visible = false;
        }

        private void displayArea_Click(object sender, EventArgs e)
        {
            this.OnClick(e);
        }

        private void displayArea_Paint(object sender, PaintEventArgs e)
        {
            var rep = Subsystem.Debugger.GetReportLength();
            if (rep == 0)
            {
                Rectangle dest = displayArea.ClientRectangle;
                Rectangle img = dest;
                img.Width = img.Height;
                dest.Width -= img.Width;
                dest.X += img.Width;
                int deflateRate = (img.Width - Properties.Resources.information.Width) / 2;
                img.Inflate(-deflateRate, -deflateRate);
                e.Graphics.DrawImage(Properties.Resources.information, img);
                TextRenderer.DrawText(e.Graphics, Lang.Main.Infobar_NoReport, this.Font, dest, this.ForeColor,
                    TextFormatFlags.EndEllipsis | TextFormatFlags.Left | TextFormatFlags.NoPrefix | TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter);
            }
            else
            {
                Rectangle dest = displayArea.ClientRectangle;
                Rectangle img = dest;
                img.Width = img.Height;
                dest.Width -= img.Width;
                dest.X += img.Width;
                int deflateRate = (img.Width - Properties.Resources.information.Width) / 2;
                img.Inflate(-deflateRate, -deflateRate);
                e.Graphics.DrawImage(Properties.Resources.exclamation, img);
                TextRenderer.DrawText(e.Graphics,
                    String.Format(Lang.Main.Infobar_ShowReport, rep)
                    , this.Font, dest, this.ForeColor,
                    TextFormatFlags.EndEllipsis | TextFormatFlags.Left | TextFormatFlags.NoPrefix | TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter);
            }
        }
    }
}
